home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4716 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.9 KB  |  67 lines

  1. Path: scream.ing.com!news
  2. From: "John C. Lund" <jlund@allaire.com>
  3. Newsgroups: comp.lang.pascal.delphi.misc,comp.lang.c++
  4. Subject: Delphi calls to a C++ DLL
  5. Date: Wed, 31 Jan 1996 14:52:27 -0600
  6. Organization: Allaire
  7. Message-ID: <310FD68B.208B@allaire.com>
  8. NNTP-Posting-Host: 206.144.133.15
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b6a (Win95; I)
  13.  
  14. I have written a DLL in C++ that I am attempting to call from a Delphi EXE. I can call 
  15. DLL functions from my C++ apps, but not from my Delphi program. The Delphi app calls the 
  16. DLL function, but most of the parameters passed are garbage. I tried the same techniques 
  17. and syntax I found in the Delphi libraries, but to no avail. 
  18.  
  19. For whatever reason it looks like the parameters are pushed and popped from the stack 
  20. differently beween environments.  I've tried declaring the function in Delphi with 
  21. "stdcall" and "cdecl", and I've tried other data types in place of pchar. Any 
  22. suggestions?
  23.  
  24.  
  25. ***************
  26. Delphi SNIPPETS
  27. ***************
  28.  
  29. {type, private}
  30. function GetFieldsForTable(
  31.    pcharDataSourceName, 
  32.    pcharUsername, 
  33.    pcharPassword, 
  34.    pcharTableName: pChar
  35.    ): integer;
  36.  
  37. {implementation}
  38. function TODBCInformant.GetFieldsForTable; 
  39.    external 'patrik.dll' name 'GetFieldsForTable';
  40.  
  41. {I call the function like this:}
  42. nIndex:= GetFieldsForTable(strpcopy(pcharBuiffer,'Test'),
  43.    strpcopy(pcharBuiffer,''),
  44.    strpcopy(pcharBuiffer,''),
  45.    strpcopy(pcharBuiffer,'Employees'));
  46.  
  47.  
  48. ************
  49. C++ SNIPPETS
  50. ************
  51.  
  52. // My C++ header (.H) declares the prototype like this:
  53. extern "C" INT FAR PASCAL EXPORT GetFieldsForTable( 
  54.    LPSTR lpszDataSourceName, 
  55.    LPSTR lpszUsername, 
  56.    LPSTR lpszPassword, 
  57.    LPSTR lpszTableName 
  58.    );
  59.  
  60. /* 
  61. My implementation uses the same format, and the function is named in the 
  62. exports section of the .DEF file.
  63. */
  64.  
  65.  
  66. // John C. Lund  jlund@allaire.com  http//:www.allaire.com/
  67.